/*
 * This file is part of the eccOS Library.
 * Copyright (C) 2007.
 *
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 */
package org.openeccos.widgets;

import org.openeccos.util.EccosDefaultLookAndFeel;

import nextapp.echo2.app.Alignment;
import nextapp.echo2.app.Border;
import nextapp.echo2.app.Color;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Font;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.Font.Typeface;
import nextapp.echo2.app.layout.GridLayoutData;
import echopointng.BorderEx;
import echopointng.LabelEx;

public class PDLabel extends LabelEx {

	public static final int PLAIN = 0;
	public static final int HEADER_1 = 1;
	public static final int HEADER_2 = 2;
	public static final int HEADER_3 = 3;
	public static final int BORDERED = 4;
	public static final int FIELD_LABEL = 5;
	public static final int FIELD_VALUE = 6;
	public static final int TABLE_HEADER_NORM = 7;
	public static final int TABLE_HEADER_LAST = 8;
	public static final int TABLE_DATA_NORM = 9;
	public static final int TABLE_DATA_LAST = 10;
	public static final int FIELD_VALUE_BORDERED = 11;

	public PDLabel(int style) {
		this(null, style, false);
	}

	public PDLabel(String text, boolean alignRight) {
		this(text, PLAIN, alignRight);
	}

	public PDLabel(String text, int style) {
		this(text, style, false);
	}

	public PDLabel(String text, int style, int width) {
		this(text, style, false);
		setWidth(new Extent(width));
	}

	public PDLabel(String text, int style, boolean alignRight) {
		super(text);
		setForeground(Color.DARKGRAY);

		switch (style) {
		case HEADER_1:
			setFont(new Font(new Typeface("Arial"), Font.BOLD + Font.ITALIC, new Extent(18)));
			break;
		case HEADER_2:
			setFont(new Font(new Typeface("Arial"), Font.PLAIN, new Extent(15)));
			break;
		case HEADER_3:
			setFont(new Font(new Typeface("Arial"), Font.BOLD, new Extent(12)));
			break;
		case BORDERED:
			setBorder(new Border(1, Color.LIGHTGRAY, Border.STYLE_SOLID));
			setInsets(new Insets(2, 2, 2, 2));
			//setHeight(new Extent(16));
			break;
		case FIELD_LABEL:
			setInsets(new Insets(5, 0));
			setFont(new Font(new Typeface("Arial"), Font.BOLD, new Extent(12)));
			break;
		case FIELD_VALUE:
			setInsets(new Insets(5, 0));
			setFont(new Font(new Typeface("Verdana"), Font.PLAIN, new Extent(12)));
			break;
		case FIELD_VALUE_BORDERED:
			setInsets(new Insets(3, 1, 0, 0));
			setHeight(new Extent(16));
			setFont(new Font(new Typeface("Verdana"), Font.PLAIN, new Extent(12)));
			setForeground(EccosDefaultLookAndFeel.DISABLED_FOREGROUND);
			setBackground(EccosDefaultLookAndFeel.DISABLED_BACKGROUND);
			setBorder(new Border(1, Color.LIGHTGRAY, BorderEx.STYLE_DOTTED));
			break;
		case TABLE_HEADER_NORM:
			setBorder(new BorderEx(0, null, 0, 1, Color.BLACK, BorderEx.STYLE_SOLID, 0, null, 0, 0, null, 0));
			setInsets(new Insets(5, 0));
			setFont(new Font(new Typeface("Arial"), Font.BOLD, new Extent(12)));
			break;
		case TABLE_HEADER_LAST:
			setInsets(new Insets(5, 0));
			setFont(new Font(new Typeface("Arial"), Font.BOLD, new Extent(12)));
			break;
		case TABLE_DATA_NORM:
			setBorder(new BorderEx(0, null, 0, 1, Color.BLACK, BorderEx.STYLE_SOLID, 0, null, 0, 0, null, 0));
			setInsets(new Insets(5, 0));
			setFont(new Font(new Typeface("Arial"), Font.PLAIN, new Extent(12)));
			break;
		case TABLE_DATA_LAST:
			setInsets(new Insets(5, 0));
			setFont(new Font(new Typeface("Arial"), Font.PLAIN, new Extent(12)));
			break;
		}

		if (alignRight) {
			GridLayoutData gld = new GridLayoutData();
			gld.setAlignment(new Alignment(Alignment.RIGHT, 0));
			setLayoutData(gld);
		}
	}

	@Override
	public void setText(String text) {
		if (text == null)
			text = "";
		super.setText(text);
	}
}
